﻿using DotNetExtensions.AspNet.DevExpress.Services;
using Habi.Solver.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Habi.Solver.Services
{

    public interface IControlOperationService
    {
        IEnumerable<string> OpenFileDialog(string filters = "", bool multi = false);
        void Quit();
        void Minimize();
        void Maximize();
    }

    public class ControlOperationService : IControlOperationService
    {
        public Control OverlayControl { get; set; }
        private IMessageService NotifyService;
        public ControlOperationService(Control overlayControl)
        {
            OverlayControl = overlayControl;
            NotifyService = new DialogMessageBoxService(OverlayControl);
        }
        public IEnumerable<string> OpenFileDialog(string filters = "", bool multi = false)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = multi;
            if (!string.IsNullOrEmpty(filters)) dialog.Filter = filters;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                return dialog.FileNames;
            }

            return new List<string>();
        }


        public void Quit()
        {
            if (NotifyService.Confirm(CommonResources.ConfirmQuit) == DialogResult.Yes)
            {
                Program.MainForm.Close();
                Application.Exit();
            }
        }

        public void Minimize()
        {
            Program.MainForm.WindowState = FormWindowState.Minimized;
        }

        public void Maximize()
        {
            Program.MainForm.WindowState = Program.MainForm.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal;
        }
    }
}
